import time

from selenium.webdriver.common.by import By

from common.base import Base
from common.function import open_browser
from page.login_page_backstage import LoginPage


class AlterPayOrder(Base):

    def bk_username(self, username):
        self.send_keys((By.NAME, 'username'), username)

    def bk_password(self, password):
        self.send_keys((By.NAME, 'password'), password)

    def login_bnt(self):
        self.click((By.CLASS_NAME, 'btn-a'))



    def alterorder1(self):#将订单修改成已付款
        self.swtich_iframe((By.ID,'menu-frame'))
        self.click((By.XPATH,'//*[@id="menu-ul"]/li[4]'))
        self.switch_to_default_content()
        self.swtich_iframe((By.ID,'main-frame'))#查看按钮
        self.click((By.XPATH,'//*[@id="listDiv"]/table[1]/tbody/tr[10]/td[7]/a'))
        self.scroll_low()
        self.click((By.XPATH,"//input[@name='pay']"))
        self.click((By.XPATH,"//textarea[@name='action_note']"))
        self.send_keys((By.XPATH,"//textarea[@name='action_note']"),'已付款')
        self.click((By.XPATH,'//input[1]'))
        self.switch_to_default_content()

    def clickorderlist(self):#点击订单列表
        time.sleep(3)
        self.swtich_iframe((By.ID,'header-frame'))
        self.click((By.XPATH,'//*[@id="menu-div"]/ul/li[4]/a'))
        self.switch_to_default_content()

    def alterorder2(self):#将订单修改成未付款
        time.sleep(3)
        self.swtich_iframe((By.ID, 'main-frame'))  # 查看按钮
        self.click((By.XPATH, '//*[@id="listDiv"]/table[1]/tbody/tr[10]/td[7]/a'))
        self.scroll_target((By.XPATH,"//input[@name='unpay']"))
        self.click((By.XPATH,"//input[@name='unpay']"))
        self.click((By.XPATH,'//textarea[@name="action_note"]'))
        self.send_keys((By.XPATH,'//textarea[@name="action_note"]'),'未付款')
        self.click((By.XPATH,"//input[@name='refund'and@value='1']"))
        self.click((By.XPATH,"//input[@class='button'and@name='submit']"))


if __name__ == '__main__':
    driver =open_browser()
    al=AlterPayOrder(driver)
    al.input_url('http://139.129.26.163/admin')
    al.bk_username('admin')
    al.bk_password('admin123')
    al.login_bnt()
    time.sleep(2)
    al.alterorder1()
    al.clickorderlist()
    al.alterorder2()


